package com.lvmama.rhino.service.impl;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lvmama.rhino.entity.PushConfigurationVO;
import com.lvmama.rhino.mapperHippo.PushConfigurationMapper;
import com.lvmama.rhino.pojo.PushConfiguration;
import com.lvmama.rhino.service.PushConfigurationService;

@Service("pushConfigurationService")
public class PushConfigurationServiceImpl implements PushConfigurationService {

    /**
     * 日志
     */
    protected Logger logger = Logger.getLogger(this.getClass());
    
    
    @Autowired
    private PushConfigurationMapper pushConfigurationMapper;

    /**
     * 推送配置管理首页面查询
     */
    @Override
	public PageInfo<PushConfiguration> queryPushConfiguration(PushConfigurationVO pushConfigurationVO) {
    	PageHelper.startPage(pushConfigurationVO.getPage(), pushConfigurationVO.getPageSize());
    	List<PushConfiguration> pushConfigurations = pushConfigurationMapper.queryPushConfiguration(pushConfigurationVO);
        logger.info("根据条件查询条件回执的配置信息pushConfiguration="+pushConfigurations);
        PageInfo<PushConfiguration> page = new PageInfo<PushConfiguration>(pushConfigurations);
        return page;
        
	}
    
    /**
     * 保存推送配置(添加和修改的)
     */
    @Override
    public void addPushConfiguration(PushConfiguration pushConfiguration) {
    	   //添加推送配置
    	Date now = new Date();
    	if(StringUtils.isBlank(pushConfiguration.getId())) {
	    	 pushConfiguration.preInsert();
	         pushConfiguration.setCreateTime(now);
	         pushConfiguration.setUpdateTime(now);
	         pushConfigurationMapper.addPushConfiguration(pushConfiguration);
    	} else {
    		//更新推送配置
    		pushConfiguration.setUpdateTime(now);
    		pushConfigurationMapper.updatePushConfiguration(pushConfiguration);
    	}
    }


    /**
     * 跳转到编辑页面, 根据id查询
     */
	@Override
	public PushConfiguration queryPushCongfigurationById(String id) {
		return pushConfigurationMapper.queryPushCongfigurationById(id);
	}


	/**
	 * 删除推送配置---暂时不用
	 */
	@Override
	public void deleteConfigurationById(String id) {
		pushConfigurationMapper.deleteConfigurationById(id);
	}


	/**
	 * 参数名称加上唯一性约束，在添加的时候要检查是否已存在相同的参数名称
	 */
	@Override
	public List<PushConfiguration> queryParameterName() {
		return pushConfigurationMapper.queryParameterName();
	}

	
}
